/*
 *  Copyright (C) 2011 glauco
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.common.defaults;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.balisunrise.annotation.PanelType;
import org.balisunrise.application.Application;
import org.balisunrise.common.*;

/**
 *
 * @author glauco
 */
public class DefaultChildren implements Children{

    private Basic owner;

    public DefaultChildren(Basic owner) {
        this.owner = owner;
    }

    @Override
    public List<Basic> getBasics() {

        List<Basic> basics = new ArrayList<Basic>();

        if(owner instanceof Application){
            Application app = Application.get();
            basics.addAll(Arrays.asList(app.getWindowsManager().getWindows()));
        }else if(owner instanceof Transaction){
            Transaction t = (Transaction)owner;
            basics.add(t.getTransactionAction());
            basics.add(t.getEditor());
            basics.add(t.getSearch());
        } else if(owner instanceof TransactionActions){
            TransactionActions ta = (TransactionActions) owner;
            basics.addAll(Arrays.asList(ta.getActions()));
        } else if(owner instanceof Editor){
            Editor e = (Editor) owner;
            basics.add(e.getMessenger());
            basics.add(e.getEntityPanel());
            basics.add(e.getEntityActions());
        } else if(owner instanceof Search){
            Search s = (Search) owner;
            basics.add(s.getEntityFilter());
            basics.add(s.getEntityGrid());
            basics.add(s.getEntityActions());
        } else if(owner instanceof Messenger){
            Messenger m = (Messenger) owner;
            // TODO: incluir mensagens
        } else if(owner instanceof EntityPanel){
            EntityPanel ep = (EntityPanel) owner;
            if(ep.getType().equals(PanelType.SINGLE))
                basics.addAll(Arrays.asList(ep.getFieldLayouts()));
            else
                basics.addAll(ep.getAssociatedPanels());
        } else if(owner instanceof EntityActions){
            EntityActions ea = (EntityActions) owner;
            basics.addAll(Arrays.asList(ea.getActions()));
        } else if(owner instanceof EntityFilter){
            EntityFilter ef = (EntityFilter) owner;
            basics.addAll(Arrays.asList(ef.getFieldLayouts()));
        } else if(owner instanceof EntityGrid){
            EntityGrid eg = (EntityGrid) owner;
            basics.add(eg.getGrid());
            basics.add(eg.getEntityLoader());
            basics.add(eg.getEntityList());
        } else if(owner instanceof Grid){
            Grid g = (Grid) owner;
            basics.add(g.getGridModel());
        } else if(owner instanceof GridModel){
            GridModel gm = (GridModel) owner;
            basics.addAll(Arrays.asList(gm.getColumns()));
        } else if(owner instanceof GridColumn){
            GridColumn gc = (GridColumn) owner;
        } else if(owner instanceof FieldLayoutGroup){
            FieldLayoutGroup flg = (FieldLayoutGroup) owner;
            basics.addAll(Arrays.asList(flg.getFieldLayouts()));
        } else if(owner instanceof FieldLayout){
            FieldLayout fl = (FieldLayout) owner;
            basics.addAll(Arrays.asList(fl.getFieldComponents()));
        }

        return basics;
    }

    @Override
    public Basic getOwner() {
        return owner;
    }

}
